package com.rework.joss.ztree.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.alibaba.fastjson.JSON;
/**
 * 
 * @ClassName. BaseController
 * @Description. TODO
 * @author zhangyang
 * @date 2016年3月24日 下午4:54:06
 * @version V1.0
 */
public class BaseController {

	
    public static final String ENCODE = "utf-8";
	
	protected void sendMessage(HttpServletResponse response, String str) throws Exception{
		response.setContentType("text/html; charset=" + ENCODE);
		PrintWriter writer = response.getWriter();
		writer.println(str);
		writer.close();
		response.flushBuffer();
	}
	/**
	 * 将某个对象转换成json格式并发送到客户端
	 * @param response
	 * @param obj
	 * @throws Exception
	 */
	protected void sendJsonMessage(HttpServletResponse response,Object obj) throws Exception{
		response.setContentType("text/html; charset=" + ENCODE);
		PrintWriter writer = response.getWriter();
		writer.println(JSON.toJSONString(obj));
		writer.close();
		response.flushBuffer();
	}
	



}
